/**
 * 泛型 - keyof
 */
interface Person {
  name: string;
  age: number;
  gender: string;
}

// class Teacher {
//   constructor(private info: Person) {}
//   getInfo(key: string) {
//     if(key === 'name' || key === 'age' || key === 'gender') {
//       return this.info[key]
//     }
//   }
// }

type NAME = 'name';
const abc: NAME = 'name' // 类型可以是字符串


class Teacher {
  constructor(private info: Person) {}
  getInfo<T extends keyof Person>(key: T): Person[T] {
    return this.info[key]
  }
}

const teacher = new Teacher({
  name: '李磊',
  age: 24,
  gender: '男'
})

const test = teacher.getInfo('age')
console.log(test)